﻿Chenxin.UI.DZFinancePayed = Chenxin.extend(Chenxin.UI.PageCommon, {
    autoInitForm: false,
    actionUrl: '/service/logic/DZFinancePayed.ashx',
    createSearch: function() {
        return new Chenxin.UI.DZFinancePayedSearch({
            scope: this
        });
    },
    showDetails: function(op, userid, depid) {
        if (!this.detailsWin) {
            this.detailsWin = new Chenxin.UI.DetailsWin({
                id: 'x_details_win',
                actionUrl: this.actionUrl
            });
        }
        this.detailsWin.show();

        this.detailsWin.setTitle('个人详情');
        this.detailsWin.grid.baseParam.op = op;
        this.detailsWin.grid.param.userid = userid;
        this.detailsWin.grid.param.depid = depid;
        Chenxin.apply(this.detailsWin.grid.param, this.search.getParamJson());
        this.detailsWin.grid.reload();
    }
});

Chenxin.UI.DetailsWin = Chenxin.extend(Chenxin.UI.Win, {
    id: '',
    actionUrl: '',
    width: 680,
    hasFoot: true,
    height: 360,
    content: '<div id="x_details_grid"></div>',
    createBtn: function() {
        return [{
            text: '关闭',
            handler: this.hide
}]
        },
        createGrid: function() {
            if (this.grid) {
                return;
            }
            this.grid = new Chenxin.UI.ReportGrid({
                baseParam: { op: '' },
                autoLoad: false,
                actionUrl: this.actionUrl,
                id: 'x_details_grid',
                renderTo: 'x_details_grid',
                hasCheckBox: false,
                cellBorder: true,
                modelId: 'a',
                scope: this,
                height: 311,
                hasTitle: false,
                columns: {
                    ContractCode: { head: '合同编号', width: 100, captionCol: true },
                    Address: { head: '房源地址', width: 300, inTotal: false },
                    BelongDepart: { head: '所属部门', width: 100, inTotal: false },
                    CurTotalPayMoney: { head: '总收支', width: 100, inTotal: false },
                    Point: { head: '点数', width: 80, inTotal: false },
                    CurPayMoney: { head: '分摊本期实收', width: 100 },
                    ProtophasePayMoney: { head: '分摊前期实收', width: 100 },
                    PayArch: { head: '实收归属', width: 100,
                        renderer: function(val, c, row) {
                            if (row.PayArchYear || row.PayArchMonth) {
                                return row.PayArchYear + '.' + row.PayArchMonth;
                            }
                            else {
                                return '';
                            }
                        }
                    },
                    ContractArch: { head: '业绩归属', width: 100,
                        renderer: function(val, c, row) {
                            if (row.ContractArchYear || row.ContractArchMonth) {
                                return row.ContractArchYear + '.' + row.ContractArchMonth;
                            }
                            else {
                                return '';
                            }
                        }
                    }
                }
            });
        },
        initComponent: function() {
            Chenxin.UI.DetailsWin.superclass.initComponent.call(this);
            this.createGrid();
        }
    });

/*
* 查询面板
*/
    Chenxin.UI.DZFinancePayedSearch = Chenxin.extend(Chenxin.UI.SearchCommon, {
        id: 'search',
        createComboList: function() {
            var _this = this;
            var combl = new Chenxin.UI.StructComboList({
                tbxWidth: 55,
                cityAfterSelected: function() {
                    comboUserId.reset();
                },
                companyAfterSelected: function() {
                    comboUserId.reset();
                },
                businessDistrictAfterSelected: function() {
                    comboUserId.reset();
                },
                departsAfterSelected: function(val) {
                    comboUserId.reset();
                    if (val != '请选择') {
                        comboUserId.loadUser(val, 500);
                    }
                }
            });
            //人员
            var comboUserId = new Chenxin.UI.RichModelTreeCombo({
                textBoxId: 'txtUser',
                inModelType: 'all',
                txtModelName: 'UserName',
                singleSelect: true,
                name: 'UserId'
            });
            var structs = combl.comboList;
            structs.push(comboUserId);
            return structs;
        },
        initEvent: function() {
            var date = new Date();
            $("#CalculateDate").focus(function() {
                WdatePicker({
                    dateFmt: 'yyyy-MM',
                    oncleared: function() {
                        $(this).blur();
                    },
                    onpicked: function() {
                        $(this).blur();
                    }
                });
            }).val(date.getFullYear() + '-' + (date.getMonth() + 1));

            var objSrh = this;
            $('.a_details').live('click', function() {
                objSrh.scope.showDetails('getdetails', $(this).attr('userid'), $(this).attr('type'));
            });

            $('#export').click(function() {
                var _this = this;
                Chenxin.Msg.Loading.show();
                Chenxin.ajax({
                    type: "get",
                    dataType: "json",
                    url: '/service/logic/DZFinancePayed.ashx',
                    data: { op: 'checkpermit', code: 'export' },
                    onSuccess: function(data) {
                        Chenxin.Msg.Loading.hide();
                        Chenxin.Fn.exportToExcel($('#search_table').html());
                    }
                });
            });
            /*********事件：检索按钮*********/
            $("#btn_search").click(function() {
                Chenxin.Msg.Loading.show();
                Chenxin.ajax({
                    type: 'get',
                    dataType: 'html',
                    url: '/service/logic/DZFinancePayed.ashx?op=getlist',
                    data: objSrh.getParamJson(),
                    onSuccess: function(data, msg) {
                        $('#search_table').empty();
                        $('#search_table').html(data.html);
                        Chenxin.Msg.Loading.hide();
                    }
                });
            });
            
            /*************************事件：生成奖金************************/
            $("#Caculate").click(function(){
                objSrh.calculate();
            });
        },
        /**
        *生成奖金
        */
        calculate:function(){
            var _this = this;
            if (!this.CalculateBonusForm) {
                this.CalculateBonusForm = new Chenxin.UI.CalculateBonusForm({
                    scrop: _this,
                    actionUrl : '/service/logic/DZFinancePayed.ashx',
                    alwaysCheckPermit: true,
                    saveSucc:function(){
			        }
                });
            }
            this.CalculateBonusForm.op = "calculatebonus";
            if(this.CalculateBonusForm.show(this.CalculateBonusForm.op)){
                this.CalculateBonusForm.reset();
                this.CalculateBonusForm.setTitle('生成奖金');
            }
        },
    });

getcity = true; //设置需要获取城市下拉框数据

$(function() {
    var objPg = new Chenxin.UI.DZFinancePayed();
});